from django.db import models
from app.validators import phone_validator
from pygments.lexers import get_all_lexers
from pygments.styles import get_all_styles

LEXERS = [item for item in get_all_lexers() if item[1]]
LANGUAGE_CHOICES = sorted([(item[1][0], item[0]) for item in LEXERS])
STYLE_CHOICES = sorted((item, item) for item in get_all_styles())
# Create your models here.


class UsersTest(models.Model):
    name = models.CharField(max_length=50)
    tel = models.CharField(max_length=12)  # , validators=[phone_validator]


class Person(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    AGE_RANGE = (
        (0, "0-10"),
        (1, "11-20"),
        (3, "21-60"),
        (4, "61-120"),
    )
    # (4, "61-120"),中数字的类型必须和下面的IntegerField类型一直
    age_range = models.IntegerField(max_length=1, choices=AGE_RANGE, help_text="this is only a test for choices")


class Musician(models.Model):
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    instrument = models.CharField(max_length=100)


class Album(models.Model):
    artist = models.ForeignKey(Musician, on_delete=models.CASCADE)
    name = models.CharField(max_length=100)
    release_date = models.DateField(null=True)
    num_stars = models.IntegerField()


class Fruit(models.Model):
    name = models.CharField(max_length=20, primary_key=True)


class Snippet(models.Model):
    created = models.DateTimeField(auto_now_add=True)
    title = models.CharField(max_length=100, blank=True, default='')
    code = models.TextField()
    linenos = models.BooleanField(default=False)
    language = models.CharField(choices=LANGUAGE_CHOICES, default='python', max_length=100)
    style = models.CharField(choices=STYLE_CHOICES, default='friendly', max_length=100)

    class Meta:
        ordering = "created"
